<?php
/**
 * league.php
 * 
 * The Session class is meant to simplify the task of keeping
 * track of logged in users and also guests.
 *
 * Written by: A. Sari
 * $Id: league.php 13 2009-07-15 15:50:05Z ahmtsari $
 * 
 */
class League
{
	var $id;
	var $league;
	var $season;	
	
	function League($i=0, $l=0, $s=0) {
		$this->id = $i;
		$this->league = $l;
		$this->season = $s;
	}
	
	function Add() {
		global $database;
		$q="INSERT INTO leagues (league, season) VALUES ('$this->league', '$this->season');";
		return $database->query($q);
	}
	
	function Delete() {
		global $database;
		$q="DELETE FROM leagues WHERE id = $this->id;";
		return $database->query($q);
		
	}
	
	function Update() {
		global $database;
		$q="UPDATE leagues SET league='$this->league', season='$this->season' WHERE id = $this->id;";
		return $database->query($q);
		
	}	
	
	function set($i=0) {
		global $database;
		if ($i==0) return 0;
		$result = $database->query("SELECT * FROM leagues WHERE Id=$i");
        if(!$result || (mysql_numrows($result) < 1)){
	        return -1; //Indicates username failure
	    }
		
		/* Retrieve password from result, strip slashes */
		$dbarray = mysql_fetch_array($result);
		$this->id = $dbarray['id'];
		$this->league = stripslashes($dbarray['league']);
		$this->season = stripslashes($dbarray['season']);
		return 1;
	}	
}
?>